<extend name="Public/base"/>

<block name="body">

	<div class="main-title">
		<h2>借款配置</h2>
	</div>

    <div class="cf">
        <div class="fl">
            <a class="btn" href="{:U('index?type=today')}">今日到期用户</a>
            <a class="btn" href="{:U('index?type=renewal')}">续期用户</a>
            <a class="btn" href="{:U('index?export=true')}">导出数据</a>
            <button class="btn kouk" >一键扣款</button>
            <button class="btn yanqi" >一键延期</button>

        </div>
        <php>
            $LOAN_STATUS = C('LOAN_STATUS');
        </php>
        <!-- 高级搜索 -->
        <div class="search-form fr cf">
            <div class="sleft">
                <div class="drop-down drop-down_type" style="width: 150px;">
                    <span id="sch-sort-txt_type"  style="width: 115px;" class="sort-txt" data="">查询类型</span>
                    <i class="arrow arrow-down"></i>
                    <ul id="sub-sch-menu_type" class="nav-list hidden">
                        <li><a href="javascript:;" style="width: 115px;" value="">查询类型</a></li>

                        <li><a href="javascript:;" style="width: 115px;" value="1">发款总额</a></li>
                        <li><a href="javascript:;" style="width: 115px;" value="2">已还款总额</a></li>
                        <li><a href="javascript:;" style="width: 115px;" value="3">待还款总额</a></li>
                    </ul>
                </div>


                <div class="drop-down drop-down1" style="width: 150px;">
                    <span id="sch-sort-txt"  style="width: 115px;" class="sort-txt" data="">状态查询</span>
                    <i class="arrow arrow-down"></i>
                    <ul id="sub-sch-menu" class="nav-list hidden">
                        <li><a href="javascript:;" style="width: 115px;" value="">状态查询</a></li>
                        <foreach name="LOAN_STATUS" item="vo" >
                            <li><a href="javascript:;" style="width: 115px;" value="{$key}">{$vo}</a></li>
                        </foreach>
                    </ul>
                </div>
                <input name="title" class="search-input" value="" placeholder="请输入名字、UID、订单号" type="text">
                <a class="sch-btn" href="javascript:;" id="search" url="{:U('index')}"><i class="btn-search"></i></a>

            </div>

            <div class="btn-group-click adv-sch-pannel fl">
                <button class="btn">高 级<i class="btn-arrowdown"></i></button>
                <div class="dropdown cf" style="display: none;">
                    <div class="row">
                        <label>查询时间：</label>
                        <input id="time-start" name="time-start" class="text input-2x" value="" placeholder="起始时间" type="text"> -
                        <input id="time-end" name="time-end" class="text input-2x" value="" placeholder="结束时间" type="text">
                    </div>
                    <div class="row">
                        <label>姓名：</label>
                        <input name="name" class="text input-2x" value="" placeholder="请输入姓名" type="text">
                    </div>
                </div>
            </div>

        </div>
    </div>

	<div class="data-table table-striped" >
		<table style="font-size:14px;">
			<thead>
				<tr>
                    <th class="row-selected row-selected"><input class="check-all" type="checkbox"/></th>
					<th>合同ID</th>
					<th>用户UID</th>
                    <th>名字</th>
                    <th>借款金额</th>
                    <th>放款金额</th>
                    <th>还款金额</th>
                    <th>借款天数</th>
                    <th>管理费</th>
                    <th>审核费</th>
                    <th>利息</th>
                    <th>申请时间</th>
                    <th>还款日期</th>
                    <th>状态</th>
                    <th >借贷记录</th>
                    <th>扣款次数</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
				<notempty name="_list">
                <php>
                   $time3 =  time()-86400;
                </php>
				<volist name="_list" id="rows">
					<tr>
                        <td><input class="ids" type="checkbox" name="id[]" value="{$rows['id']}" /></td>
                        
						<td>{$rows['id']}</td>
						<td>{$rows['uid']}</td>
                        <td>{$rows['name']}</td>
                        <td>{$rows['money']}</td>
                        <td>{$rows['payable']}</td>
                        <td>{$rows['repayment']}</td>
                        <td>{$rows['day']}</td>
                        <td>{$rows['manag']}</td>
                        <td>{$rows['vetting1']}</td>
                        <td>{$rows['accrual']}</td>
                        <td>{$rows['create_time']|date='Y-m-d H:i:s',###}</td>
                        <td>
                            <notempty name="rows['expire_time']">
                                <span >{$rows['expire_time']|date='Y-m-d H:i:s',###}
                                </span>
                            </notempty></td>
						<td>
                            {$LOAN_STATUS[$rows['status']]}
                        </td>
                        <td>
                            <php>
                                $one=D('Loan')->where("uid=".$rows['uid'])->select();
                                $jkcs=count($one);
                                $two=D('Loan')->where(['status'=>6,'uid'=>$rows['uid']])->select();
                                $ashk=0;
                                $yq=0;
                                foreach($two as $key=>$val){
                                    $date1=date("Ymd",$val['expir_time']);
                                    $date2=date("Ymd",$val['huankuan_time']);
                                    if(strtotime($date1)>=strtotime(date2)){
                                        $ashk=$ashk+1;
                                    }else{
                                        $yq=$yq+1;
                                    }

                                }
                                $three=D('Loan')->where(['status'=>3,'uid'=>$rows['uid']])->select();
                                $btg=count($three);
                                $four=D('Loan')->where(['status'=>5,'uid'=>$rows['uid']])->select();
                                $dhk=count($four);
                            </php>
                            <p >借贷总数：{$jkcs}</p>
                            <p >按时还款：{$ashk}</p>
                            <p >逾期还款：{$yq}</p>
                            <p >待还款：  {$dhk}</p>
                            <p >不通过：  {$btg}</p>
                            


                        </td>
                        <td>{$rows['kk_count']}</td>
						<td>

                            &nbsp;&nbsp;
							<a title="详细" href="{:U('view?id='.$rows['id'])}">详细</a>
						</td>
					</tr>
				</volist>
				<else/>
				<td colspan="14" class="text-center"> aOh! 暂时还没有内容! </td>
				</notempty>
			</tbody>
		</table>
        <div class="" style="padding-top: 10px;">
            <div style="float: left;" class="">借款金额：<span style="color: #ff3366">{$sum.money}</span>元</div>
            <div style="float: left;padding-left: 50px;" class="">放款金额：<span style="color: #ff6600">{$sum.payable}</span>元</div>
            <div style="float: left;padding-left: 50px;" class="">还款金额：<span style="color: #0000ff">{$sum.repayment}</span>元</div>
            <div style="float: left;padding-left: 50px;" class="">管理费：<span style="color: #c43c35">{$sum.manag}</span>元</div>
            <div style="float: left;padding-left: 50px;" class="">审核费：<span style="color: #AF2018">{$sum.vetting1}</span>元</div>
            <div style="float: left;padding-left: 50px;" class="">利息：<span style="color: #c67605">{$sum.accrual}</span>元</div>
        </div>



	</div>

    <div class="page"  style="float:left;margin-right:300px;">{$_page}</div>
</block>

<block name="script">
    <link href="/Public/static/datetimepicker/css/datetimepicker.css" rel="stylesheet" type="text/css">
    <link href="/Public/static/datetimepicker/css/dropdown.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="/Public/static/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
    <script type="text/javascript" src="/Public/static/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
<script type="text/javascript">
    $(function(){
        //搜索功能
        $("#search").click(function(){
            var url = $(this).attr('url');
            var status = $("#sch-sort-txt").attr("data");
            var type   = $("#sch-sort-txt_type").attr("data");
            var query  = $('.search-form').find('input').serialize();
            query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
            query = query.replace(/^&/g,'');
            if(status != ''){
                query += '&status=' + status + "&" + query;
            }
            if(type != ''){
                query += '&type=' + type + "&" + query;
            }
            if( url.indexOf('?')>0 ){
                url += '&' + query;
            }else{
                url += '?' + query;
            }
            window.location.href = url;
        });





        /* 状态搜索子菜单 */
        $(".search-form").find(".drop-down1").hover(function(){
            $("#sub-sch-menu").removeClass("hidden");
        },function(){
            $("#sub-sch-menu").addClass("hidden");
        });
        $("#sub-sch-menu li").find("a").each(function(){
            $(this).click(function(){
                var text = $(this).text();
                $("#sch-sort-txt").text(text).attr("data",$(this).attr("value"));
                $("#sub-sch-menu").addClass("hidden");
            })
        });

        $(".search-form").find(".drop-down_type").hover(function(){
            $("#sub-sch-menu_type").removeClass("hidden");
        },function(){
            $("#sub-sch-menu_type").addClass("hidden");
        });

        $("#sub-sch-menu_type li").find("a").each(function(){
            $(this).click(function(){
                var text = $(this).text();
                $("#sch-sort-txt_type").text(text).attr("data",$(this).attr("value"));
                $("#sub-sch-menu_type").addClass("hidden");
            })
        });
        $('#time-start').datetimepicker({
            format: 'yyyy-mm-dd',
            language:"zh-CN",
            minView:2,
            autoclose:true
        });

        $('#time-end').datetimepicker({
            format: 'yyyy-mm-dd',
            language:"zh-CN",
            minView:2,
            autoclose:true
        });




        $('.kouk').click(function(){
            obj = document.getElementsByClassName("ids");
            // console.log(obj)
            check_val = [];
            for(k in obj){
                if(obj[k].checked)
                    check_val.push(obj[k].value);
            }
            $.ajax({
                type:'post',
                data:{'ids':check_val},
                // dataType:'json',
                url:"index.php?m=admin&c=capital&a=kouk",
                success:function(m){
                    alert(m)
                        // alert("提交扣款人数："+ids+"，成功："+success+"，失败："+default+"。失败合同号："+ht+"对应失败原因："+error)
                }
            })
        })




        $('.yanqi').click(function(){
            alert(0)
        })












    })


</script>
</block>